#!/usr/bin/env node

const EventEmitter = require('./');

class Dog extends EventEmitter{
  constructor(name,energy){
    super();
    this.#name = name;
    this.#energy = energy;
    this.#startTimer();
  }

  setEnergy(e){
    this.#evergy = e;
    this.#startTimer();
  }

#startTimer(){
  if(this.#timer != null) return;


  this.#timer = setInterval(function(){
    if(this.#energy > 0){
      this.emit('bark');
      this.#energy --;
    }else{
      clearInterval(this.#timer);
      this.#timer = null;
    }
  },1000)

}

  #name = '';
  #enery = 0;
  #timer = null;


  get name(){
    return this.#name;
  }

  get energy(){
    return this.#energy;
  }
}

module.exports = Dog;
